home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / B-C / C++Source Code Fmtr Folder / Tests / TestCases < prev    next >
Encoding:
Text File  |  1991-04-29  |  9.8 KB  |  550 lines  |  [TEXT/MPS ]

  1. /* There is a "\n" after the "{" */
  2. int a[] = {1,2,3,4};
  3.  
  4. /* The "T::*a" was being emitted as "T ::*a" */
  5. void (Target::*aMethod)(int);
  6.  
  7. /* The "b" appears flush left in the output instead of being indented */
  8. int a,// comment
  9. b;
  10. Rect a,// More commentary
  11. b;
  12.  
  13. /* The following causes a rescan.  The rescan screws up */
  14. void ObjectTable::IObjectTable(PageTable*     aPageTable,
  15.                           unsigned short firstPage,
  16.                           unsigned long  nObjectsInFile,
  17.                           unsigned short objectSize)
  18.  
  19.  
  20. /* The "," yields ",  " instead of ", " */
  21. foo(){int a,b;}
  22.  
  23. /*
  24. this is a comment
  25.  
  26. with a blank line
  27. */
  28.  
  29. int x = {
  30.     /*
  31.     ** a comment
  32.     */
  33.     1,
  34.     "abcdefghijklmnopqrstuvwxyz",
  35.     "abcdefghijklmnopqrstuvwxyz",
  36.     "abcdefghijklmnopqrstuvwxyz",
  37.     "abcdefghijklmnopqrstuvwxyz",
  38.     "abcdefghijklmnopqrstuvwxyz",
  39.     "abcdefghijklmnopqrstuvwxyz",
  40.     "abcdefghijklmnopqrstuvwxyz",
  41.     "abcdefghijklmnopqrstuvwxyz",
  42.     "abcdefghijklmnopqrstuvwxyz",
  43.     "abcdefghijklmnopqrstuvwxyz",
  44.     "abcdefghijklmnopqrstuvwxyz",
  45.     "abcdefghijklmnopqrstuvwxyz",
  46.     "abcdefghijklmnopqrstuvwxyz",
  47.     "abcdefghijklmnopqrstuvwxyz",
  48.     "abcdefghijklmnopqrstuvwxyz",
  49.     "abcdefghijklmnopqrstuvwxyz",
  50.     "abcdefghijklmnopqrstuvwxyz",
  51.     "abcdefghijklmnopqrstuvwxyz",
  52.     "abcdefghijklmnopqrstuvwxyz",
  53.     "abcdefghijklmnopqrstuvwxyz",
  54. };
  55.  
  56. // The "int x;" is indented.  Why is that?
  57. RedoPageBreaks()
  58. {
  59.     a,  b;
  60.     a,  b;
  61. }
  62. int x;
  63.  
  64.  
  65. foo(){return x;return (foo*)(x);}
  66. aType foo(OSType fileCreator // a comment
  67.     ){}
  68. foo(){do ch = NextChar();while ((ch > 0) && (ch != '\n'));}
  69.  
  70. foo(){*a++==&p;a=-1;*a++=&p;*a++==&p;- -q;}
  71.  
  72. static short    itemList[] =
  73. {
  74.     3,                                    /* max number of items - 1 */
  75.  
  76.     /*
  77.     ** statText item
  78.     */
  79.     0, 0,                                /* reserve a Longint for item handle */
  80.     10, 27, 61, 225,                    /* display rectangle */
  81.     ((8 + 128) << 8) | 8,                /* 8 + 128 = statText (disabled), title 8 bytes long */
  82.     '^0', '^1',                         /* ^0^1^2^3 */
  83.     '^2', '^3',
  84.  
  85.     /*
  86.     ** first button
  87.     */
  88.     0, 0,                                /* reserve a Longint for item handle */
  89.     104, 140, 124, 210,                 /* display rectangle */
  90.     (4 << 8) | 0,                        /* 4 = pushButton, title is 0 bytes long*/
  91.  
  92.     /*
  93.     ** second button
  94.     */
  95.     0, 0,                                /* reserve a Longint for item handle */
  96.     104, 30, 124, 100,                    /* display rectangle */
  97.     (4 << 8) | 0,                        /* 4 = pushButton, title is 0 bytes long */
  98.  
  99.     /*
  100.     ** third button
  101.     */
  102.     0, 0,                                /* reserve a Longint for item handle */
  103.     72, 30, 92, 100,                    /* display rectangle */
  104.     (4 << 8) | 0                        /* 4 = pushButton, title is 0 bytes long */
  105. };
  106.  
  107. class
  108. {
  109.     String()        {}
  110.         // Return the string in the token itself
  111. };
  112.  
  113.  
  114. foo ()
  115.     {
  116.     if (q)
  117.         {
  118.         }
  119.  
  120.     // Skip over the white space
  121.     Fnord();
  122.                 //ƒ-
  123.             /*ƒ-turn off comments
  124.     */
  125.         a(b,    c,         d);
  126.     //ƒ+
  127.     a(b, c,     d);a(b, c,     d);a(b, c,     d);a(b, c,     d);
  128.     }
  129.  
  130.  
  131. #define    initialMasters      1024        /* masters pointers to reserve at startup 
  132.                                                     up from 700 kc 7/20/90 */
  133.  
  134.  
  135. typedef struct OpEntry {            /* Operator table entry */
  136.     TokenKind operator;                /*        token type (LeftParen, Plus, …) */
  137.     unsigned char precedence;        /*        operator precedence */
  138.     OpKind    opKind;                    /*        operator type (unary, binary, …) */
  139.     OperandKind operandKind;        /*        type of operands (string, integer, …) */
  140.     State (*expectOperandFn)();    /*        routine to call when expecting operand */
  141.     State (*expectOpFn)();            /*        routine to call when expecting operator */
  142. } OpEntry;
  143.  
  144.  
  145. pjDiskInsert(EventRecord* pEvent, PCommonStruct pCommon)
  146. {
  147.     short            drive;
  148.     VCB            *pVCB;
  149.     QHdrPtr        qHead;
  150.     short            vol;
  151.         
  152.     if (pCommon->type == CheckInWindow || pCommon->type == NewProjectWindow
  153. #ifndef BROWSER
  154.         )
  155. #else
  156.         || pCommon->type == kBrowserWindow)
  157. #endif
  158.         {
  159. // if private is not specified, set public by default
  160. // (first verify that we can't get here with them both set)
  161.     BugAssert((!opt.private || !opt.public), "Public & private options are equal!");
  162.     opt.public  = !(opt.private);
  163.         }
  164.     fixThis();
  165. #if 0
  166.     else {
  167.         updateNamePopup(projectIndex);
  168.     }
  169. #endif
  170.         }
  171.  
  172.  
  173.  
  174. #ifdef ghs
  175. pascal void
  176. scrollText(hScroll, thePart)
  177. ControlHandle    hScroll;                                                /* scroll bar's handle */
  178. short                thePart;                                                /* the part of the control the mouse is in */
  179. #else
  180. pascal void scrollText(ControlHandle hScroll, short thePart)
  181. #endif
  182.     {
  183.     }
  184.  
  185.  
  186.  
  187. foo()
  188. {
  189.     if(1){}
  190.     else;
  191.                 if (1) ; else if (1) ; else if (1) {}
  192.                 else if (1)
  193.                     {} else { gCrashCause = kBreakPoint;
  194.                     }
  195.  
  196.                     if (maxBytesOnCont == 6)
  197.                         TABTO(hexcodeCol - 1)
  198.                     else
  199.                         TABTO(hexcodeCol + 5 - 1)
  200.  
  201.     struct {
  202.     unsigned        inFindNextMode : 1; } sally;
  203. }
  204.  
  205.  
  206. foo(int a, int b)
  207. {
  208.     short targetSize, maskSize, e, m, t;
  209.     char* inputBuffer = new char[inputSize+1];
  210.     }
  211.  
  212.  
  213.  
  214.  
  215. typedef struct                            // OpndInfo set up by Interpret's Get1Opnd
  216.     {
  217.     } OpndInfo, *pOpndInfo;
  218.     
  219.  
  220. typedef pascal OSErr (*VNProcPtr)(VolumeNoticeBlkPtr pParams);
  221.  
  222.     void*                operator()();
  223.  
  224.  
  225. #ifdef __cplusplus
  226. extern "C" {
  227. #endif __cplusplus
  228. pascal SetFont(unsigned char *fName, short fontKind, short fontSize);
  229.     /*
  230.     Set the MPW editor font kind and size.  No errors are returned of this
  231.     operation fails.
  232.     */
  233.  
  234. #ifdef    __cplusplus
  235. }
  236. #endif    __cplusplus
  237.  
  238.  
  239.  
  240. typedef struct FILE_REFERENCE                    FILE_REFERENCE;
  241.  
  242. foo(){TTE_INFO type1, type2, type3;}
  243.  
  244.  
  245. struct{};
  246.  
  247. enum
  248.     {
  249.       kSErr    =   -1                // Error token
  250.     , kSLex =    0                // Base enum for scanner generated tokens
  251.     , kSPrs = 1000                // Base class for parser generated items
  252.     };
  253.  
  254.  
  255.     operator FILE*()                const        {return (fFile);}
  256.  
  257.  
  258.  
  259. class Formatting;
  260.  
  261.  
  262. extern void diag(Severity, const char*, ...);        /* Report errors    */
  263.  
  264.  
  265. #define CASE(a)        case a: return (#a);
  266. const char*
  267. Parser::NameOf(short aType)
  268.     {
  269.     switch (aType)
  270.         {
  271.     CASE(kSPrs_DeclOperator)
  272.     
  273.     default:    return "<unknown token>";
  274.         }
  275.     }
  276.  
  277.  
  278.  
  279. foo(){}
  280.  
  281.  
  282. Parser::~Parser()
  283.     {}
  284.  
  285.  
  286.  
  287.  
  288. foo()
  289. {
  290.     static const short handles[] =
  291.         {
  292.          4,    kSLex_Id,            4,    kSLex_Id,            kSLex_ClassColon,    kSLex_OpBNot,    kSPrs_Id,
  293.  
  294.         -1, -1,                    0
  295.         };
  296. }
  297.  
  298.  
  299. foo()
  300. {
  301.     for (;;)
  302.         {
  303.         ch=NextChar();
  304.         }
  305. }
  306.  
  307.  
  308.  
  309. foo()
  310. {
  311.     if (strncmp((char*)fBuffer-1, "if", 2)==0)
  312.         type=kSLex_PoundIf;
  313.     else if (strncmp((char*)fBuffer-1, "endif", 5)==0)
  314.         type=kSLex_PoundEndIf;
  315.  
  316.     ;;;
  317. }
  318.  
  319.  
  320. foo()
  321. {
  322.             if (strncmp((char*)fBuffer-1, "if", 2)==0)
  323.     for (;;)
  324.         {
  325.         ch=NextChar();
  326.         if (ch=='\\'&&NextChar()=='\n')
  327.             continue;
  328.         if (IsEOF()||ch=='\n')
  329.             {
  330.             if (ch=='\n')
  331.                 PushBack();
  332.             return (new CommentToken(type, start, fBuffer));
  333.             }
  334.         if (findFirstWord&&!isspace(ch))
  335.             {
  336.             findFirstWord=false;
  337.             if (strncmp((char*)fBuffer-1, "if", 2)==0)
  338.                 type=kSLex_PoundIf;
  339.             else if (strncmp((char*)fBuffer-1, "elif", 4)==0)
  340.                 type=kSLex_PoundElif;
  341.             else if (strncmp((char*)fBuffer-1, "else", 4)==0)
  342.                 type=kSLex_PoundElse;
  343.             else if (strncmp((char*)fBuffer-1, "endif", 5)==0)
  344.                 type=kSLex_PoundEndIf;
  345.             }
  346.         }
  347.     }
  348.  
  349. foo()
  350. {
  351.     while (isxdigit(ch))
  352.         ch = NextChar();
  353. }
  354.  
  355.  
  356. static PredefinedToken gClassColon    (kSLex_ClassColon,    "::");
  357.  
  358. static unsigned char   gErrText[] = "——— Error ———";
  359. static LexicalToken    gErr            (kSErr,                gErrText, gErrText+13);
  360.  
  361. void
  362. CommentToken::Display(Formatting* aFormat)
  363.     {
  364.     switch (Type())
  365.         {
  366.     case kSLex_Comment:
  367.         aFormat->Comment((const char*)fStart, (const char*)fEnd);
  368.         break;
  369.         
  370.     case kSLex_PoundIf:
  371.     case kSLex_PoundElif:
  372.     case kSLex_PoundElse:
  373.     case kSLex_PoundEndIf:
  374.     case kSLex_PoundOther:
  375.         /*
  376.         ** Assure that the preprocessor line starts on a fresh line
  377.         */
  378.         aFormat->FreshLine();
  379.         // !!! FALL THROUGH !!!
  380.         
  381.     default:
  382.         aFormat->Write((char*)fStart, fEnd-fStart);
  383.         break;
  384.         }
  385.     }
  386.  
  387.  
  388.  
  389. /*
  390. ** Define the types that parse items can be.
  391. */
  392. enum
  393.     {
  394.       kSLex_ParsedId    = kSLex_Last+1    // The "id" has been parsed.
  395.     , kSLex_Flush                        // Unblocks Prs_Id/Prs_DeclOperator
  396.  
  397.     , kSPrs_Id            = kSPrs            // Base parse type
  398.     , kSPrs_StmtList
  399.     , kSPrs_DeclList
  400.     , kSPrs_DeclType
  401.     , kSPrs_Stmt
  402.     , kSPrs_Decl
  403.     , kSPrs_Do
  404.     , kSPrs_If
  405.     , kSPrs_Else
  406.     , kSPrs_For
  407.     , kSPrs_Struct
  408.     , kSPrs_Switch
  409.     , kSPrs_While
  410.     , kSPrs_Expr
  411.     , kSPrs_DeclOperator
  412.     };
  413.  
  414.  
  415. /*
  416. ** LexicalToken
  417. **    This class represents tokens whose body is in the CScanner buffer itself
  418. */
  419. class LexicalToken : public SyntacticLex
  420.     {
  421. public:
  422.     LexicalToken(short aType, TextPtr start)
  423.         : SyntacticLex(aType)
  424.         , fStart(start)
  425.         , fEnd(start+strlen((char*)start))
  426.         {}
  427.  
  428.     LexicalToken(short aType, short aMinorType, TextPtr start)
  429.         : SyntacticLex(aType, aMinorType)
  430.         , fStart(start)
  431.         , fEnd(start+strlen((char*)start))
  432.         {}
  433.         
  434.     LexicalToken(short aType, TextPtr start, TextPtr end)
  435.         : SyntacticLex(aType)
  436.         , fStart(start)
  437.         , fEnd(end)
  438.         {}
  439.  
  440.     LexicalToken(short aType, short aMinorType, TextPtr start, TextPtr end)
  441.         : SyntacticLex(aType, aMinorType)
  442.         , fStart(start)
  443.         , fEnd(end)
  444.         {}
  445.  
  446.     virtual void Display(Formatting* aFormat);
  447.         /*
  448.         ** Display the token using the formatting information given by
  449.         ** aFormat
  450.         */
  451.     
  452. protected:
  453.     TextPtr fStart;
  454.     TextPtr fEnd;
  455.     };
  456.  
  457.  
  458. void
  459. LexicalToken::Display(Formatting* aFormat)
  460.     {
  461.     aFormat->Write((char*)fStart, fEnd-fStart);
  462.     }
  463.  
  464.  
  465.  
  466.  
  467. class SyntacticLex : public Syntactic
  468.     {
  469. public:
  470.     SyntacticLex(int aType, int aMinorType=0)
  471.         : Syntactic(aType, aMinorType)
  472.         {}
  473.  
  474.  
  475.     virtual Boolean IsSeparator() const;
  476.         /*
  477.         ** Return true.
  478.         */
  479.  
  480.     virtual const Syntactic* SaveCopy() const;
  481.         /*
  482.         ** The object cannot be modified by any of its methods, so
  483.         ** return itself.
  484.         */
  485.         
  486.     virtual void Display(Formatting* aFormat) = 0;
  487.         /*
  488.         ** Format and display this syntactic item.  The format to use when
  489.         ** displaying is passed in as its only argument.
  490.         */
  491.     };
  492.  
  493. #define CASE(x)        {#x, &gFS_##x},
  494. static Boolean
  495. isFormatOption(int argc, char* argv[], int i)
  496.     {
  497.     if (i+1 >= argc)
  498.         return (false);
  499.         
  500.     const char* aName = argv[i]+1;
  501.     const char* aFormat = lower(argv[i+1]);
  502.  
  503.     static struct Option
  504.         {
  505.         const char*   fName;
  506.         FormatString* fString;
  507.         } options[] =
  508.         {
  509.         CASE(fundef2)
  510.         CASE(fundef3)
  511.         CASE(fundef4)
  512.         CASE(fundef6)
  513.         CASE(fundef7)
  514.         CASE(fundef8)
  515.         CASE(fundef10)
  516.         CASE(fundef11)
  517.         CASE(fundef12)
  518.         CASE(fundef13)
  519.         CASE(fundef14)
  520.         
  521.         CASE(decl0)
  522.         CASE(decl1)
  523.         CASE(decl2)
  524.         CASE(decl3)
  525.         CASE(decl5)
  526.         CASE(decl6)
  527.         CASE(decl7)
  528.         CASE(decl8)
  529.         CASE(decl9)
  530.         CASE(decl10)
  531.         CASE(decl11)
  532.         {0, 0}
  533.         };
  534.  
  535.     return (false);
  536.     }
  537.  
  538.  
  539. Boolean
  540. SyntacticLex::IsSeparator()    const
  541.     {
  542.     return (false);
  543.     }
  544.  
  545.  
  546. const Syntactic*
  547. SyntacticLex::SaveCopy()    const
  548.     {
  549.     return (this);
  550.     }